/**
 * Created by dale on 2017/10/26.
 */
var silder;
$(document).ready(function () {
    try{
        window.top.chageColor('#134c79');
    }catch (Expection){

    }
    initBanner();
    var width=$(window).width()/4.0;  //初始化处理
    $('#gridView .row div').each(function () {
        $(this).attr('style','height:'+width+'px;');
    });
    window.onresize = function(){  //重新定义界面大小处理
        var width=$(window).width()/4.0;
        $('#gridView .row div').each(function () {
            $(this).attr('style','height:'+width+'px;');
        })
    };


    $.ajax({  //权限验证
        url:baseUrl+'mobile/shortcut/getModule',
        type:'POST',
        dataType:'json',
        async:false,
        success:function (data) {
            $.each(data,function (index,value) {
                var target = $($('#gridView .row div')[index]);

                var str    = '<a   module="'+value['module']+'"   class="easyui-linkbutton" ';
                    if(value['attr'] !=null){
                        $.each(value['attr'],function (key,value) {
                           str += ' '+key+'="'+value+'" ';
                        });
                    }
                    str+= ' data-options="iconCls:\''+value['iconClass']+'\',size:\'large\',iconAlign:\'top\',plain:true" style="height:100%;width: 100%">'+value['name']+'</a>';
                target.append(str);
            });
            $.parser.parse($('#gridView'));
        },
        error:function (data) {
            console.log(data);
        }
    });




    $('#gridView').on('click','.easyui-linkbutton',function () {
        
        var module = $(this).attr('module');
        var title  = $(this).find('.l-btn-text').text();
        if(module == 'boxIn'||module == 'boxOut'||module == 'reportDev'){
            $('#targetFrame',window.parent.document).attr('src',baseUrl+'ims/moblie/'+module);
        }else if(module == 'student'||module == 'teacher'){
            var userType = 0;
            if(module == 'student'){
                userType = 1; //学生
            }else {
                userType = 4; //老师
            }
            title +='-学校列表';
            $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/shortcut/schList?type='+userType);
        } else if (module == 'getTab'){//领用
            var type = $(this).attr('type');
            $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/shortcut/getTab?type='+type);
        } else {
            $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/shortcut/'+module);
        }

        $('#targetPanel-title',window.parent.document).html(title);
        window.parent.goTarget();
    });

});

function initBanner() {
    $.ajax({
        url:baseUrl+'mobile/index/getBanner',
        dataType:'json',
        type:'post',
        success:function (data) {
            $('.flexslider').empty();
            var str = '<ul class="slides">';
            $.each(data,function (i,item) {
                str += '<li><img src="'+item['img']+'" targetUrl="'+item['url']+'"  stusColor="'+item['color']+'" style="width:100%;"></li>';
            });
            str +='</ul>';
            $('.flexslider').append(str);
            silder = $('.flexslider').flexslider({
                animation: 'slide',
                animationLoop: true, //是否循环播放
                controlNav: false,
                directionNav: false,
                startAt: 0, // Integer: 开始播放的 slide，从 0 开始计数
                slideshow: true, // Boolean: 是否自动播放
                slideshowSpeed: 3000, // Integer: ms 滚动间隔时间
                animationSpeed: 600, // Integer: ms 动画滚动速度
                animationDuration: 600,
                direction: "vertical",
                before: function(){
                    var color =$('.flexslider').find('.flex-active-slide').next().find('img').attr('stuscolor');
                    try{
                        window.top.chageColor(color);
                    }catch (e){

                    }
                }
            });
        },
        error: function (res) {
            window.top.sendErrorMsg(res['error']);
        }
    });
}